package cn.rongdao.jrkabao.ui.remind.treeviewbinder;

import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRCollection;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.remind.RemindBillBean;
import cn.rongdao.jrkabao.treeview.TreeNode;

/**
 * Created by zxy on 17/4/23
 */

public class SecondLevelNodeViewBinder extends CheckableNodeViewBinder {

    private TextView tvDate;
    private TextView tvMoney;
    private View viewLine;

    SecondLevelNodeViewBinder(View itemView) {
        super(itemView);
        tvDate = (TextView) itemView.findViewById(R.id.irsl_tv_date);
        tvMoney = (TextView) itemView.findViewById(R.id.irsl_tv_money);
        viewLine = itemView.findViewById(R.id.irsl_view_line);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_remind_second_level;
    }

    @Override
    public void bindView(final TreeNode treeNode) {
        RemindBillBean remindBillBean = (RemindBillBean) treeNode.getValue();
        tvMoney.setText(FRString.valueOf(remindBillBean.getBills_amount()));
        tvDate.setText(getTextContent(remindBillBean.getBills_date(), remindBillBean.getBills_desc()));
    }

    private SpannableString getTextContent(String billDate, String billDesc) {
        String content = FRCollection.appendAsString(billDate, "\n", billDesc, "");
        SpannableString ss = new SpannableString(content);
        if (FRString.isEmpty(billDate)) {
            ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.c999999)), 0, billDate.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
            ss.setSpan(new AbsoluteSizeSpan(11, true), 0, billDate.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        }
        return ss;
    }
}